#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 1e5 + 10;
typedef long long LL;
LL tree1[N], tree2[N], arr[N];
int n, t, m;
int lowbit(int x)
{
	return x & -x;
}

void add(LL tree[], int x, int c)
{
	for (int i = x; i <= n; i += lowbit(i)) {
		tree[i] += c;
	}
}

LL sum(LL tree[], int x)
{
	LL res = 0;
	for (int i = x; i; i -= lowbit(i)) {
		res += tree[i];
	}
	return res;
}

LL get_sum(int x)
{
	return sum(tree1, x) * (x + 1) - sum(tree2, x);
}
int main()
{
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		memset(arr, 0, sizeof(arr));
		memset(tree1, 0, sizeof(tree1));
		memset(tree2, 0, sizeof(tree2));
		for (int i = 1; i <= n; i++) {
			scanf("%d", &arr[i]);
			int d = arr[i] - arr[i - 1];
			add(tree1, i , d);
			add(tree2, i , i * d);
		}
		scanf("%d", &m);
		while (m--) {
			int temp;
			scanf("%d", &temp);
			int l, r;
			scanf("%d%d", &l, &r);
			if (temp == 1) {
				add(tree1, l, lowbit(arr[l]));
				add(tree1, r + 1, -(lowbit(arr[l])));
				add(tree2, l, lowbit(arr[l]) * l);
				add(tree2, r + 1, -(lowbit(arr[l]) * (r + 1)));
			}
			else {
				cout << get_sum(r) - get_sum(l - 1) << endl;
			}
		}
	}
	return 0;
}